
package com.cuiyongzhi.web.start;

import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

import org.apache.log4j.Logger;

import com.cuiyongzhi.web.util.GlobalConstants;
import com.cuiyongzhi.wechat.controller.WechatSecurity;

/**
 * ClassName: InterfaceUrlInti
 * @Description: 项目启动初始化方法
 * @author dapengniao
 * @date 2016年3月10日 下午4:08:21
 */
public class InterfaceUrlInti {
	private static Logger logger = Logger.getLogger(WechatSecurity.class);
	public synchronized static void init(){
		ClassLoader cl = Thread.currentThread().getContextClassLoader();
		Properties props = new Properties();
		if(GlobalConstants.interfaceUrlProperties==null){
			GlobalConstants.interfaceUrlProperties = new Properties();
		}
		InputStream in = null;
		try {
			in = cl.getResourceAsStream("interface_url.properties");
			props.load(in);
			logger.info(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+">>>>>> 开始初始化微信接口......");
			for(Object key : props.keySet()){
				logger.info(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+">>>>>> "+key+"="+props.get(key));
				GlobalConstants.interfaceUrlProperties.put(key, props.get(key));
			}
			
			props = new Properties();
			in = cl.getResourceAsStream("wechat.properties");
			props.load(in);
			logger.info(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+">>>>>> 开始初始化微信参数......");
			for(Object key : props.keySet()){
				GlobalConstants.interfaceUrlProperties.put(key, props.get(key));
				logger.info(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+">>>>>> "+key+"="+props.get(key));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(in!=null){
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return;
	}

}
